import 'package:chathouse/pages/expert/buyWallet/recharge_bank_card.dart';
import 'package:chathouse/pages/route_manager/root_route_manager.dart';
import 'package:chathouse/public/Config.dart';
import 'package:chathouse/util/base_utils.dart';
import 'package:flutter/material.dart';

import '../../../chat/chat_page.dart';
import '../../../model/expert_message.dart';
import '../../../model/member_info.dart';
import '../../../util/log.dart';

/// @class : CommentOrderPage
/// @date : 2023-02-28 17:12
/// @name : LFC
/// @description :服務商資料頁面

class ExpertDataPage extends StatefulWidget {
  // var projectId;
  // var isShowBottomBar;
  Rows item;

  ExpertDataPage(this.item, {Key? key}) : super(key: key);

  @override
  State<ExpertDataPage> createState() => _ExpertDataPageState();
}

class _ExpertDataPageState extends State<ExpertDataPage> with NavigationHelper {
  TextEditingController controller = TextEditingController();
  var selectedStars = 0.0;
  MemberInfo? _memberInfo;

  static List<String> fourStarExpertPhoneList = [
    "85255087779",
    "85291604776",
    "85269339111",
    "85261102161",
    "85296656332",
    "8619928459816",
    "85269981054",
  ];
  String? services;

  @override
  void initState() {
    super.initState();
    getMembersInfo();
  }

  getMembersInfo() {
    Obj.showLoading();
    Apis.getMembersInfoForNo(widget.item.adverseNo).then((value) {
      // print('getMembersInfoForNo value');
      // print(value.toString());
      Obj.dismissLoading();
      var jsonData = value?.data;
      _memberInfo = MemberInfo.fromJson(jsonData);

      String phone = _memberInfo?.data?.membersPhone??'';
      if(phone.isNotEmpty && fourStarExpertPhoneList.indexWhere((element) => element == phone) != -1){
        services = "四星優質師父";
      }else{
        services = _memberInfo?.data?.serviceName ?? "";
      }

      LogUtil.d("getMembersInfo success ");
      setState(() {});
    }).catchError((error) {
      Obj.dismissLoading();
      LogUtil.d("getMembersInfo error");
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        resizeToAvoidBottomInset: false,
        backgroundColor: Colors.white,
        appBar: AppBar(
          backgroundColor: Colors.white,
          shadowColor: Colors.transparent,
          leading: Icon(
            Icons.arrow_back_ios,
            size: 28.w,
            color: MyColors.gary_149149149,
          ).setOnClickListener(() {
            Get.back();
          }),
          centerTitle: true,
          title: Text(
            "服務商資料",
            textAlign: TextAlign.center,
            style: getTextStyle(28.sp,
                color: Colors.black, fontType: FontType.BOLD),
          ),
        ),
        body: ListView(
          children: [
            Container(
              alignment: Alignment.center,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Container(
                      alignment: Alignment.center,
                      padding: EdgeInsets.only(top: 20.w, bottom: 20.w),
                      decoration: BoxDecoration(
                          color: MyColors.gary_243244246,
                          borderRadius: BorderRadius.circular(16.w)),
                      constraints:
                          BoxConstraints(minHeight: 132.w, maxWidth: 300.w),
                      margin: EdgeInsets.only(top: 12.w),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          Row(
                            mainAxisSize: MainAxisSize.min,
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              ImageUtils.image(
                                      _memberInfo?.data?.memberImage ?? "",
                                      width: 65.w,
                                      height: 65.w,
                                      imageType: ImageType.NETWORK,
                                      radius: 36.w)
                                  .setContainer(),
                              SizedBox(
                                width: 10.w,
                              ),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Text(
                                    _memberInfo?.data?.membersName ?? "",
                                    style: getTextStyle(18.sp,
                                        fontType: FontType.BOLD),
                                  ),
                                  Text(
                                      // _memberInfo?.data?.serviceName ?? "",
                                      services??'',
                                      style: getTextStyle(14.sp,
                                          fontType: FontType.BOLD,
                                          color: MyColors.gary_112112112)),
                                  // Text("ID: ${widget.item.membersNo}" ?? "",
                                  //     style: getTextStyle(14.w,
                                  //         fontType: FontType.BOLD,
                                  //         color: MyColors.gary_112112112)),
                                ],
                              ).setContainer(
                                  constraints: BoxConstraints(maxWidth: 140.w)),
                            ],
                          ),
                          Row(
                            mainAxisSize: MainAxisSize.min,
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              ImageUtils.image(
                                      _memberInfo?.data?.memberImage ?? "",
                                      width: 65.w,
                                      height: 0.w,
                                      imageType: ImageType.NETWORK,
                                      radius: 36.w)
                                  .setContainer(),
                              SizedBox(
                                width: 10.w,
                              ),
                              Text(
                                "優質服務商",
                                style: getTextStyle(12.sp,
                                    color: Colors.black,
                                    fontType: FontType.BOLD),
                              )
                                  .setContainer(
                                      width: 82.w,
                                      margin: EdgeInsets.only(top: 10.w),
                                      alignment: Alignment.center,
                                      decoration: BoxDecoration(
                                          color: Colors.white,
                                          border: Border.all(
                                              color: MyColors.gary_112112112,
                                              width: 1.w),
                                          borderRadius:
                                              BorderRadius.circular(10.w)))
                                  .setContainer(
                                      constraints:
                                          BoxConstraints(maxWidth: 140.w)),
                            ],
                          ),
                          SizedBox(width: 6.w),
                        ],
                      )),
                  SizedBox(
                    height: 16.w,
                  ),
                  // Container(
                  //   alignment: Alignment.centerLeft,
                  //   margin: EdgeInsets.only(left: 60.w),
                  //   child: Text("聯絡方式",
                  //       style: getTextStyle(16.sp,
                  //           fontType: FontType.MID, color: Styles.c_666)),
                  // ),
                  // SizedBox(
                  //   height: 4.w,
                  // ),
                  // Container(
                  //   margin: EdgeInsets.only(left: 60.w),
                  //   alignment: Alignment.centerLeft,
                  //   child: Text("+${_memberInfo?.data?.membersPhone ?? ""}",
                  //       style: getTextStyle(16.sp,
                  //           fontType: FontType.MID, color: Styles.c_666)),
                  // ),
                  // SizedBox(
                  //   height: 16.w,
                  // ),
                  Container(
                    margin: EdgeInsets.only(left: 60.w),
                    alignment: Alignment.centerLeft,
                    child: Text("聯絡即時線上對話",
                        style: getTextStyle(16.sp,
                            fontType: FontType.MID, color: Styles.c_666)),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 40.w),
                    alignment: Alignment.center,
                    child: Container(
                      padding:
                          EdgeInsets.symmetric(vertical: 8.w, horizontal: 40.w),
                      decoration: BoxDecoration(
                          color: MyColors.gary_24916231,
                          borderRadius: BorderRadius.circular(20.w)),
                      child: Text(
                        "聯絡即時線上對話",
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: 19.w,
                            fontWeight: FontWeight.w600),
                      ),
                    ),
                  ).setOnClickListener(() {
                    Map map = {
                      "reviceuserId": widget.item.adverseNo,
                      "projectNo": widget.item.projectNo,
                      "memberImage": widget.item.memberImage,
                      "membersName": widget.item.adverseName,
                      "evaluate": widget.item.evaluate,
                      "exhibition": widget.item.exhibition,
                      "projectId": widget.item.projectId
                    };
                    LogUtil.d("map $map");
                    Get.off(ChatPage(map));
                    // Get.to(ChatPage(map));
                  })
                ],
              ),
            ),
          ],
        ));
  }
}
